dcmotor28fng 2.2.1
Loading...
Searching...
No Matches
dcmotor28fng


DC Motor 28 FNG Click

DC Motor 28 FNG Click demo application is developed using the NECTO Studio, ensuring compatibility with mikroSDK's open-source libraries and tools. Designed for plug-and-play implementation and testing, the demo is fully compatible with all development, starter, and mikromedia boards featuring a mikroBUS™ socket.


Click Library

  • Author : Stefan Filipovic
  • Date : Jan 2025.
  • Type : ADC type

Software Support

Example Description

This example demonstrates the use of the DC Motor 28 FNG Click board. It initializes the Click driver, calibrates the offset for accurate current measurements, and then controls the motor in different states while measuring and logging the output current in milliamps (mA).

Example Libraries

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.DCMotor28FNG

Example Key Functions

Application Init

Initializes the logger and the DC Motor 28 FNG Click driver and performs offset calibration for current measurements.

void application_init ( void )
{
log_cfg_t log_cfg;
dcmotor28fng_cfg_t dcmotor28fng_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
dcmotor28fng_cfg_setup( &dcmotor28fng_cfg );
if ( ADC_ERROR == dcmotor28fng_init( &dcmotor28fng, &dcmotor28fng_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
if ( DCMOTOR28FNG_ERROR == dcmotor28fng_calib_offset ( &dcmotor28fng ) )
{
log_error( &logger, " Offset calibration." );
for ( ; ; );
}
log_info( &logger, " Application Task " );
}
@ DCMOTOR28FNG_ERROR
Definition dcmotor28fng.h:172
#define DCMOTOR28FNG_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition dcmotor28fng.h:120
void application_init(void)
Definition main.c:39
#define MIKROBUS_POSITION_DCMOTOR28FNG
Definition main.c:33

Application Task

Controls the motor in a sequence of states: FORWARD, BRAKE, REVERSE, and COAST. In each state, the output current is measured and logged, providing insights into the motor's performance and consumption.

void application_task ( void )
{
float current = 0;
log_printf( &logger, " Motor state : FORWARD\r\n" );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
if ( DCMOTOR28FNG_OK == dcmotor28fng_get_out_current ( &dcmotor28fng, &current ) )
{
log_printf( &logger, " Current : %.3f mA\r\n\n", current );
}
log_printf( &logger, " Motor state : BRAKE\r\n" );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
if ( DCMOTOR28FNG_OK == dcmotor28fng_get_out_current ( &dcmotor28fng, &current ) )
{
log_printf( &logger, " Current : %.3f mA\r\n\n", current );
}
log_printf( &logger, " Motor state : REVERSE\r\n" );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
if ( DCMOTOR28FNG_OK == dcmotor28fng_get_out_current ( &dcmotor28fng, &current ) )
{
log_printf( &logger, " Current : %.3f mA\r\n\n", current );
}
log_printf( &logger, " Motor state : COAST\r\n" );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
if ( DCMOTOR28FNG_OK == dcmotor28fng_get_out_current ( &dcmotor28fng, &current ) )
{
log_printf( &logger, " Current : %.3f mA\r\n\n", current );
}
}
@ DCMOTOR28FNG_OK
Definition dcmotor28fng.h:171
#define DCMOTOR28FNG_MOTOR_COAST
DC Motor 28 FNG motor PWM control mode setting.
Definition dcmotor28fng.h:99
#define DCMOTOR28FNG_MOTOR_BRAKE
Definition dcmotor28fng.h:102
#define DCMOTOR28FNG_MOTOR_FORWARD
Definition dcmotor28fng.h:100
#define DCMOTOR28FNG_MOTOR_REVERSE
Definition dcmotor28fng.h:101
void application_task(void)
Definition main.c:75

Note

Ensure the PMODE switch is set to position 1 (HIGH), the motor is properly connected to the board OUT1 and OUT2 terminals, and the proper power supply is connected to the input terminal.

Application Output

This Click board can be interfaced and monitored in two ways:

  • Application Output - Use the "Application Output" window in Debug mode for real-time data monitoring. Set it up properly by following this tutorial.
  • UART Terminal - Monitor data via the UART Terminal using a USB to UART converter. For detailed instructions, check out this tutorial.

Additional Notes and Information

The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.